/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managerBeans;

import entity.Users;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author Minh Luc
 */
@ManagedBean
@SessionScoped
public class System implements Serializable {

    public static Users user;
    public static boolean Admin = false;
    public static boolean Manager = false;
    public static boolean Employee = false;
    public static boolean AdminAndManager = false;
    public static boolean ManagerAndEmployee = false;
    public static boolean Login = false;

    public void Reset() {
        // Tạo Ra Reset toàn bộ hệ thống...... Code cuối
    }

    public void Permission() {
        if (user != null) {
            PermissionDefault();
            if (user.getRoles().getRoleName().equalsIgnoreCase("Administration")) {
                PermissionAdmin();
            } else if (user.getRoles().getRoleName().equalsIgnoreCase("Manager")) {
                PermissionManager();
            } else if (user.getRoles().getRoleName().equalsIgnoreCase("Employee")) {
                PermissionEmployee();
            } else {
                PermissionDefault();
            }
        } else {
            PermissionDefault();
        }
    }

    private void PermissionDefault() {
        Login = false;
        Admin = false;
        Manager = false;
        Employee = false;
        AdminAndManager = false;
        ManagerAndEmployee = false;
    }

    private void PermissionAdmin() {
        Login = true;
        Admin = true;
        AdminAndManager = true;
    }

    private void PermissionManager() {
        Login = true;
        AdminAndManager = true;
        ManagerAndEmployee = true;
        Manager = true;
    }

    private void PermissionEmployee() {
        Login = true;
        Employee = true;
        ManagerAndEmployee = true;
    }

    public Users getUser() {
        return user;
    }

    public void setUser(Users aUser) {
        user = aUser;
    }

    public boolean isAdmin() {
        Permission();
        return Admin;
    }

    public boolean isManager() {
        Permission();
        return Manager;
    }

    public boolean isEmployee() {
        Permission();
        return Employee;
    }

    public boolean isAdminAndManager() {
        Permission();
        return AdminAndManager;
    }

    public boolean isManagerAndEmployee() {
        Permission();
        return ManagerAndEmployee;
    }

    public boolean isLogin() {
        Permission();
        return Login;
    }
}
